package beans;

import java.util.*;

public class UIBlock {

	/**
	 * id:algorithmId or modelId
	 */
	private String id;
	private String blockId;
	private boolean isAlgorithm;
	private Object algorithmOrModel;
	public List<UIInputConfig> inputConfig;
	public List<UIParamConfig> paramConfig;
	/**
	 * key: previous block id
	 * value: previous object 1: is algorithm    0: is model
	 */
	public Map<String,Integer> preBlockMap;
	/**
	 * key: post block id
	 * value: post object 1: is algorithm    0: is model
	 */
	public Map<String,Integer> postBlockMap;

	
	
	
	public UIBlock() {
		super();
		this.postBlockMap = new HashMap<>();
		this.preBlockMap = new HashMap<>();
		this.inputConfig = new ArrayList<>();
		this.paramConfig = new ArrayList<>();
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public boolean isAlgorithm() {
		return isAlgorithm;
	}
	public void setAlgorithm(boolean isAlgorithm) {
		this.isAlgorithm = isAlgorithm;
	}
	public String getBlockId() {
		return blockId;
	}
	public void setBlockId(String blockId) {
		this.blockId = blockId;
	}
	@Override
	public String toString() {
		String pre = "";
		Iterator<Map.Entry<String,Integer>> iterator = preBlockMap.entrySet().iterator();
		for(Map.Entry<String, Integer> pree:preBlockMap.entrySet()){
			pre += pree.getKey()+":"+pree.getValue()+"\t";
		}
		"uiyog".hashCode();
		String post = "";
		for(Map.Entry<String, Integer> postt:postBlockMap.entrySet()){
			post += postt.getKey()+":"+postt.getValue()+"\t";
		}
		String inputs = "";
		for(UIInputConfig in:this.inputConfig){
			inputs += in.toString()+"\n";
		}
		String params = "";
		for(UIParamConfig p: this.paramConfig){
			params += p.toString()+"\n";
		}
		return "UIBlock :id=" + id + ", blockId=" + blockId + ", isAlgorithm=" + isAlgorithm + "\n\t preBlockMap="
				+ pre + "\n\t postBlockMap=" + post + "\n\t\t "+inputs+"\n\t\t"+params;
	}

	public HashMap<String,String> getParamMap(){
		HashMap<String,String> result = new HashMap<>();
		for(UIParamConfig oneParam:this.paramConfig){
			result.put(oneParam.getParamName(),oneParam.getParamValue());
		}
		return result;
	}

	public Object getAlgorithmOrModel() {
		return algorithmOrModel;
	}

	public void setAlgorithmOrModel(Object algorithmOrModel) {
		this.algorithmOrModel = algorithmOrModel;
	}
//	public HashMap<String,Integer> getPreAlgorithmMap(){
//		HashMap<String,Integer> result = new HashMap<>();
//		for(Map.Entry<String,Integer> oneParam:this.preBlockMap.entrySet()){
//			if(oneParam.getKey().contains("uiStart"))
//		}
//
//		return result;
//	}
}
